package org.example;

import ws.schild.jave.Encoder;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import ws.schild.jave.encode.VideoAttributes;

import java.io.File;
import java.util.Date;
/**
 * @author zoush
 * @createTime 2024/11/28  14:47
 */
public class TestDemo {
    public static void main(String[] args) {
        File source = new File("E:\\FFOutput\\7fb3dd101c6efe7973be02ce85bcf09a.avi");
        File target = new File("E:\\FFOutput\\7fb3dd101c6efe7973be02ce85bcf09a.mp4");
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame"); //音频编码格式
        audio.setBitRate(800000);
        audio.setChannels(1);
        VideoAttributes video = new VideoAttributes();
        video.setCodec("libx264");//视频编码格式
        video.setBitRate(3200000);
        video.setFrameRate(15);//数字设置小了，视频会卡顿
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setInputFormat("avi");
        attrs.setOutputFormat("mp4");
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        MultimediaObject multimediaObject = new MultimediaObject(source);
        try {
            System.out.println("avi转MP4 --- 转换开始:" + new Date());
            encoder.encode(multimediaObject, target, attrs);
            System.out.println("avi转MP4 --- 转换结束:" + new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
